import React, { Component } from "react";
import {
  Link,
  Route,
  Switch,
  useHistory,
  // useParams,
  // useLocation,
  // useRouteMatch,
} from "react-router-dom";

const Home = () => {
  // const history = useHistory();
  // console.log(history);
  // const params = useParams();
  // console.log(params);
  // const location = useLocation();
  // console.log(location);
  // const match = useRouteMatch();
  // console.log(match);

  const history = useHistory();
  const fn = () => {
    // console.log(history);
    history.push("/about");
  };

  return <div onClick={fn}>首页</div>;
};
class About extends Component {
  render() {
    return <div>关于页</div>;
  }
}
class Mine extends Component {
  render() {
    return <div>我的页</div>;
  }
}

// Hooks是react16.8版本新增的
// 让函数组件具有类组件的功能
// 解决了高阶组件的组件嵌套问题
// 注意: 所有的hooks都要函数组件的顶层

class Basic extends Component {
  state = {};
  render() {
    return (
      <>
        <h3>路由hooks</h3>
        <ul>
          <li>
            <Link to="/home/444">home</Link>
          </li>
          <li>
            <Link to="/about">about</Link>
          </li>
          <li>
            <Link to="/mine">mine</Link>
          </li>
        </ul>

        <Switch>
          <Route path="/home/:id">
            <Home />
          </Route>
          <Route path="/about" component={About}></Route>
          <Route path="/mine" component={Mine}></Route>
        </Switch>
      </>
    );
  }
}

export default Basic;
